package com.atguigu.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.member.feign.MemberOrderFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Classname MemberWebController
 * @Description TODO
 * @Date 2021/10/21 16:14
 * @Author Anonymous
 */
@Controller
@SuppressWarnings("all")
@Slf4j
public class MemberWebController {

    @Resource
    private MemberOrderFeignService memberOrderFeignService;

    @RequestMapping(value = "/memberOrder.html")
    //从页面传入参数，当前是第几页，每页有多少记录
    public String orderList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, Model model, HttpServletRequest request) {
        //可以获取到支付宝给我们传来的请求数据
        //http://member.gulimall.com/memberOrder.html?charset=utf-8&
        // out_trade_no=202110221441087671451438455066779649&
        // method=alipay.trade.page.pay.return&total_amount=14400.00&
        // sign=M5XM9lDwMQKmR8gELW7zV0IRFekJk7WZ4ONIipaCewPjqPmvBaWdunHOVm85%2FfznNjlYePoYQc2H909%2Fig8XJIEUNuByr1h21%2BVdyx8wK3ltaM%2Bp%2BF4Ds2KhMclqgPodeqQVgrfHpjxwrFYWFt%2BvWrjDJARoZDa9XPNvP9dMf9Q9%2BrlPwB1u%2FEGP9fvLM7ypTdme%2FkzKKLvQ1BH1wHMf6TcWLQifsX4hPYt4oVit15vc8imPhDXiffGQ9g1vg5EvrXVVhpsxFI4Fs%2BKBuBY%2BoZ46U%2F573dz%2FCZ848gLdGu394jcW1tmKbWTbEfAS9Ne9wYbzC7yBaC2%2FgI9LAcvLZw%3D%3D&trade_no=2021102222001484260501357285&auth_app_id=2021000118635886&version=1.0&app_id=2021000118635886&sign_type=RSA2&seller_id=2088621956702121&timestamp=2021-10-22+14%3A41%3A32
        //request.验证签名
        Map<String, Object> page = new HashMap<>();
        page.put("page", pageNum.toString());
        //html相当于页面访问，feign调用请求头会丢失，配置feign的拦截器即可
        R r = memberOrderFeignService.listWithItem(page);
        model.addAttribute("orders", r);
//		支付宝返回的页面数据
        System.out.println(JSON.toJSONString(r));
        return "orderList";
    }
}
